<?php
/************************** Variables that need changing *********************/
$environment = 'sandbox';														// or 'live'
$payment = 100;																	// payment amount
$description = "Test Paypal website pro"; 										// description
$api_username = 'wpp_1231559369_biz_api1.gmail.com';							// api username
$api_password = '1231559379';													// api password
$api_signature = 'ATMxGVXigIvz9-eORM27vjIH560nAvnk91oLYuUKsothxXHO87HJA46w';	// api signature
/************************** End of varialbes that need changing **************/

$message = "";
$success = true;
if(isset($_POST['submit'])){
	foreach($_POST as $field => $value){
		if(empty($value)){
			$message .= "<i>$field</i>, ";
			$success = false;
		}
	}
	if($success){
		// Set request-specific fields.
		$paymentType = urlencode('Sale');				// or 'Authorization'
		$firstName = urlencode($_POST['accFirstName']);
		$lastName = urlencode($_POST['accLastName']);
		$creditCardType = urlencode($_POST['ccType']);
		$creditCardNumber = urlencode($_POST['ccNumber']);
		$expDateMonth = $_POST['ccExpireMonth'];
		// Month must be padded with leading zero
		$padDateMonth = urlencode(str_pad($expDateMonth, 2, '0', STR_PAD_LEFT));

		$expDateYear = urlencode($_POST['ccExpireYear']);
		$cvv2Number = urlencode($_POST['ccSecurityCode']);
		$address1 = urlencode($_POST['adLine1']);
		$address2 = urlencode($_POST['adLine2']);
		$city = urlencode($_POST['adCity']);
		$state = urlencode($_POST['adState']);
		$zip = urlencode($_POST['adZip']);
		$country = urlencode($_POST['adCountry']);				// US or other valid country code
		$currencyID = urlencode('USD');							// or other currency ('GBP', 'EUR', 'JPY', 'CAD', 'AUD')

		// Add request-specific fields to the request string.
		$nvpStr =	"&PAYMENTACTION=$paymentType&AMT=$payment&CREDITCARDTYPE=$creditCardType&ACCT=$creditCardNumber".
					"&EXPDATE=$padDateMonth$expDateYear&CVV2=$cvv2Number&FIRSTNAME=$firstName&LASTNAME=$lastName".
					"&STREET=$address1&STREET2=$address2&CITY=$city&STATE=$state&ZIP=$zip&COUNTRYCODE=$country&CURRENCYCODE=$currencyID";
		$nvpStr .= "&DESC=$description";


		// Execute the API operation; see the PPHttpPost function above.
		$httpParsedResponseAr = PPHttpPost('DoDirectPayment', $nvpStr, $environment, $api_username, $api_password, $api_signature);

		if(isset($httpParsedResponseAr["ACK"]) && "Success" == $httpParsedResponseAr["ACK"]) {
			$message = 'Payment Completed Successfully !!! ';
			$success = true;
		} else  {
			$message = 'Payment Failed: <br />';
			$success = false;
			if(isset($httpParsedResponseAr['L_LONGMESSAGE0'])){
				$message .= urldecode($httpParsedResponseAr['L_LONGMESSAGE0']);
			}
			else{
				$message .= $httpParsedResponseAr['fatal_error'];
			}
		}
	}else{
		$message = "The fields " . $message . " must be filled <br />";
	}
}

/**
 * Send HTTP POST Request
 *
 * @param	string	The API method name
 * @param	string	The POST Message fields in &name=value pair format
 * @return	array	Parsed HTTP Response body
 */
function PPHttpPost($methodName_, $nvpStr_, $environment, $api_username, $api_password, $api_signature) {

	// Set up your API credentials, PayPal end point, and API version.
	$API_UserName = urlencode($api_username);
	$API_Password = urlencode($api_password);
	$API_Signature = urlencode($api_signature);
	$API_Endpoint = "https://api-3t.paypal.com/nvp";
	if("sandbox" === $environment || "beta-sandbox" === $environment) {
		$API_Endpoint = "https://api-3t.$environment.paypal.com/nvp";
	}
	$version = urlencode('51.0');

	// Set the curl parameters.
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
	curl_setopt($ch, CURLOPT_VERBOSE, 1);

	// Turn off the server and peer verification (TrustManager Concept).
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_POST, 1);

	// Set the API operation, version, and API signature in the request.
	$nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_";
	// Set the request as a POST FIELD for curl.
	curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);

	// Get response from the server.
	$httpResponse = curl_exec($ch);

	if(!$httpResponse) {
		$httpParsedResponseAr['fatal_error'] = "$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')';
	}

	// Extract the response details.
	$httpResponseAr = explode("&", $httpResponse);

	$httpParsedResponseAr = array();
	foreach ($httpResponseAr as $i => $value) {
		$tmpAr = explode("=", $value);
		if(sizeof($tmpAr) > 1) {
			$httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
		}
	}

	if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
		$httpParsedResponseAr['fatal_error'] = "Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.";
	}

	return $httpParsedResponseAr;
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Paypal checkout</title>
<link href="./css/pp.css" rel="stylesheet" type="text/css" />
</head>
<body>

<form name="checkout" id="checkout" method="post" action="pp_checkout.php">
<fieldset>
<div class="<?php if($success) echo "message"; else echo "errors";?>"><?php echo $message;?></div>
<table>
	<tr>
		<th colspan="2">
		<h2>Enter Credit Card/Billing Information <span
			class="requiredNote"><span class="required"><br />
		*</span>Required field</span></h2>
		</th>
	</tr>
	<tr>
		<td width="30%"><label>First Name:<span>*</span></label></td>
		<td><input name="accFirstName"  id="accFirstName" maxlength="15"
			id="id4" msg="msgFirstName" class="text required" tabindex="150"
			type="text"></td>
	</tr>
	<tr>
		<td><label>Last Name:<span>*</span></label></td>
		<td><input name="accLastName"  id="accLastName" maxlength="15"
			id="id5" msg="msgLastName" class="text required" tabindex="160"
			type="text"></td>
	</tr>
	<tr>
		<td><label>Address Line 1:<span>*</span></label></td>
		<td><input name="adLine1"  id="adLine1" maxlength="30"
			id="id6" msg="msgAddrLine1" class="text required" tabindex="190"
			type="text"></td>
	<tr>
		<td class="row"><label> Address Line 2:</label></td>
		<td><input name="adLine2"  id="adLine2" maxlength="30"
			class="text" tabindex="200" type="text"></td>
	</tr>
	<tr>
		<td class="row required"><label> City:<span>*</span></label></td>
		<td><input name="adCity"  id="adCity" maxlength="35"
			id="id7" msg="msgCity" class="text required" tabindex="220"
			type="text"></td>
	</tr>
	<tr>
		<td class="row required"><label> State/Province:<span>*</span></label></td>
		<td><select name="adState"  id="adState" tabindex="230">
							<option value="00">Not in US</option>
							<option value="AL">Alabama</option>

							<option value="AK">Alaska</option>

							<option value="AS">American Samoa</option>

							<option value="AZ">Arizona</option>

							<option value="AR">Arkansas</option>

							<option value="CA">California</option>

							<option value="CO">Colorado</option>


							<option value="CT">Connecticut</option>

							<option value="DE">Delaware</option>

							<option value="DC">District of Columbia</option>

							<option value="FM">Federated States of Micronesia</option>

							<option value="FL">Florida</option>

							<option value="GA">Georgia</option>


							<option value="GU">Guam</option>

							<option value="HI">Hawaii</option>

							<option value="ID">Idaho</option>

							<option value="IL">Illinois</option>

							<option value="IN">Indiana</option>

							<option value="IA">Iowa</option>


							<option value="KS">Kansas</option>

							<option value="KY">Kentucky</option>

							<option value="LA">Louisiana</option>

							<option value="ME">Maine</option>

							<option value="MH">Marshall Islands</option>

							<option value="MD">Maryland</option>


							<option value="MA">Massachusetts</option>

							<option value="MI">Michigan</option>

							<option value="MN">Minnesota</option>

							<option value="MS">Mississippi</option>

							<option value="MO">Missouri</option>

							<option value="MT">Montana</option>


							<option value="NE">Nebraska</option>

							<option value="NV">Nevada</option>

							<option value="NH">New Hampshire</option>

							<option value="NJ">New Jersey</option>

							<option value="NM">New Mexico</option>

							<option value="NY">New York</option>


							<option value="NC">North Carolina</option>

							<option value="ND">North Dakota</option>

							<option value="MP">Northern Mariana Islands</option>

							<option value="OH">Ohio</option>

							<option value="OK">Oklahoma</option>

							<option value="OR">Oregon</option>


							<option value="Z1">Other</option>

							<option value="PW">Palau</option>

							<option value="PA">Pennsylvania</option>

							<option value="PR">Puerto Rico</option>

							<option value="RI">Rhode Island</option>

							<option value="SC">South Carolina</option>


							<option value="SD">South Dakota</option>

							<option value="TN">Tennessee</option>

							<option value="TX">Texas</option>

							<option value="UT">Utah</option>

							<option value="VT">Vermont</option>

							<option value="VI">Virgin Islands</option>


							<option value="VA">Virginia</option>

							<option value="WA">Washington</option>

							<option value="WV">West Virginia</option>

							<option value="WI">Wisconsin</option>

							<option value="WY">Wyoming</option>

				</select>
		</td>
	</tr>
	<tr>
		<td class="row required"><label> ZIP/Postal Code:<span>*</span></label></td>
		<td><input name="adZip"  id="adZip" msg="msgZip" maxlength="15"
			 class="text required zip" tabindex="240"
			type="text"></td>
	</tr>
	<tr>
		<td class="row required"><label> Country:<span>*</span></label></td>
		<td><select name="adCountry"  id="adCountry" id="id9" class="required"
			msg="msgCountry" tabindex="250">
			<option value="AL">Albania</option>

			<option value="AI">Anguilla</option>

			<option value="AG">Antigua and Barbuda</option>


			<option value="AR">Argentina</option>

			<option value="AM">Armenia</option>

			<option value="AW">Aruba</option>

			<option value="AU">Australia</option>

			<option value="AT">Austria</option>

			<option value="AZ">Azerbaijan</option>


			<option value="BS">Bahamas</option>

			<option value="BB">Barbados</option>

			<option value="BE">Belgium</option>

			<option value="BZ">Belize</option>

			<option value="BM">Bermuda</option>

			<option value="BO">Bolivia</option>


			<option value="BR">Brazil</option>

			<option value="BN">Brunei Darussalam</option>

			<option value="CA">Canada</option>

			<option value="KY">Cayman Islands</option>

			<option value="CL">Chile</option>

			<option value="CO">Colombia</option>


			<option value="CK">Cook Islands</option>

			<option value="CR">Costa Rica</option>

			<option value="DK">Denmark</option>

			<option value="DO">Dominican Republic</option>

			<option value="EC">Ecuador</option>

			<option value="FO">Faeroe Islands</option>


			<option value="FJ">Fiji</option>

			<option value="FI">Finland</option>

			<option value="FR">France</option>

			<option value="GF">French Guiana</option>

			<option value="PF">French Polynesia</option>

			<option value="DE">Germany</option>


			<option value="GI">Gibraltar</option>

			<option value="GR">Greece</option>

			<option value="GL">Greenland</option>

			<option value="GP">Guadelope</option>

			<option value="HT">Haiti</option>

			<option value="HK">Hong Kong</option>


			<option value="IN">India</option>

			<option value="IE">Ireland</option>

			<option value="IL">Israel</option>

			<option value="IT">Italy</option>

			<option value="JP">Japan</option>

			<option value="KE">Kenya</option>


			<option value="KR">Korea, Republic of</option>

			<option value="LS">Lesotho</option>

			<option value="LI">Liechtenstein</option>

			<option value="LU">Luxembourg</option>

			<option value="MO">Macau</option>

			<option value="MG">Madagascar</option>


			<option value="MY">Malaysia</option>

			<option value="MT">Malta</option>

			<option value="MH">Marshall Islands</option>

			<option value="MQ">Martinique</option>

			<option value="MU">Mauritius</option>

			<option value="MX">Mexico</option>


			<option value="MC">Monaco</option>

			<option value="NA">Namibia</option>

			<option value="NL">Netherlands</option>

			<option value="AN">Netherlands Antilles</option>

			<option value="NC">New Caledonia</option>

			<option value="NZ">New Zealand</option>


			<option value="NO">Norway</option>

			<option value="PY">Paraguay</option>

			<option value="PE">Peru</option>

			<option value="PH">Philippines</option>

			<option value="PT">Portugal</option>

			<option value="RE">Reunion</option>


			<option value="BL">Saint Barthelemy</option>

			<option value="KN">Saint Kitts and Nevis</option>

			<option value="SM">San Marino</option>

			<option value="SG">Singapore</option>

			<option value="ZA">South Africa</option>

			<option value="ES">Spain</option>


			<option value="SR">Suriname</option>

			<option value="SZ">Swaziland</option>

			<option value="SE">Sweden</option>

			<option value="CH">Switzerland</option>

			<option value="TH">Thailand</option>

			<option value="TR">Turkey</option>


			<option value="AE">United Arab Emiirates</option>

			<option value="GB">United Kingdom</option>

			<option value="US" selected="selected">United
			States</option>

			<option value="VU">Vanuatu</option>

			<option value="VG">Virgin Islands, British</option>

			<option value="VN">Viet Nam</option>

			<option value="ZW">Zimbabwe</option>


		</select></td>
	</tr>
	<tr>
	</tr>
	<tr>
		<td colspan="2" align="center"><img
			src="./images/creditcardicons.gif" alt="Credit Card Logos" border="0"
			height="23" vspace="8" width="205"></td>
	</tr>
	<tr>
		<td class="row required"><label for="ccType">Card Type: <span>*</span></label></td>
		<td><select name="ccType"  id="ccType" tabindex="90">
			<option value="MasterCard">MasterCard</option>
			<option value="Amex">American Express</option>
			<option value="Discover">Discover</option>
			<option value="Visa">Visa</option>
		</select></td>
	</tr>
	<tr>
		<td class="row required"><label for="ccNumber">Card
		Number: <span>*</span></label></td>
		<td><input class="text" name="ccNumber"  id="ccNumber" size="20" maxlength="20"
			autocomplete="off" tabindex="100" type="text"></td>
	</tr>
	<tr>
		<td class="row required"><label for="ccExpDateMonth">Expiration
		Date:<span>*</span></label></td>
		<td><select name="ccExpireMonth"  id="ccExpireMonth" id="ExpMonthID" tabindex="110">
			<option selected="selected" value="">Month</option>
			<option value="01">01 - JAN</option>
			<option value="02">02 - FEB</option>
			<option value="03">03 - MAR</option>
			<option value="04">04 - APR</option>
			<option value="05">05 - MAY</option>
			<option value="06">06 - JUN</option>
			<option value="07">07 - JUL</option>
			<option value="08">08 - AUG</option>
			<option value="09">09 - SEP</option>
			<option value="10">10 - OCT</option>
			<option value="11">11 - NOV</option>
			<option value="12">12 - DEC</option>
		</select>
		<select name="ccExpireYear"  id="ccExpireYear" id="ExpYearID" tabindex="120">
			<option value="">Year</option>
			<option value="2009">2009</option>
			<option value="2010">2010</option>
			<option value="2011">2011</option>
			<option value="2012">2012</option>
			<option value="2013">2013</option>
			<option value="2014">2014</option>
			<option value="2015">2015</option>
			<option value="2016">2016</option>
			<option value="2017">2017</option>
			<option value="2018">2018</option>
			<option value="2019">2019</option>
		</select></td>
	<tr>
		<td class="row required" id="securityCodeRow"><label
			for="ccSecurity">Security Code:<span>*</span></label></td>
		<td><input class="text" maxlength="4" name="ccSecurityCode"  id="ccSecurityCode"
			size="4" tabindex="130" type="password"><br>
		</td>
	</tr>
	<tr>
		<td colspan="2" align="center">
		<p>Your credit card's security code is a 3- or 4-digit number
		located on its front or back.
		</td>
	</tr>
	<tr>
		<td colspan="2" align="center"><img src="./images/cc_visa.jpg"
			alt="" border="0"> <img src="./images/cc_amex.jpg" alt=""
			border="0"> <img src="./images/cc_discover.jpg" alt=""
			border="0"></td>
	</tr>
	<tr>
		<td colspan="2" align="center"><input type="submit" onclick="return validate();" value="Submit" name="submit"  id="submit" /></td>
	</tr>


</table>
</fieldset>
</form>

</body>
</html>